package admin

import (
	"easyblog/logicals"
	"easyblog/utils/errmsg"
	"github.com/beego/beego/v2/server/web"
)

type UploadController struct {
	web.Controller
}

// @router /admin/upload [post]
func (this *UploadController)UploadImage(){
	f, h, _ := this.GetFile("image")
	defer f.Close()

	code, url := logicals.UploadImage(f, h)

	result := map[string]interface{}{
		"code":code,
		"message": errmsg.GetErrmsg(code),
		"url": url,
	}

	this.Data["json"] = result
	this.ServeJSON()
}